#encoding:utf8 


import os
import sys

libs = [
    "coreex"
]

install_flist = [
    "coreex.d.ts", 
    "coreex.js", 
]


def build():    
    for lib in libs:
        tpwd = os.path.join(os.getcwd(), "runtime", "libs", lib)
        os.chdir(tpwd)
        print("Building lib-><%s>..."%lib)
        os.system("tsc -p ./tsconfig.json")
 



def comile_and_move(pname):
    pwd = os.getcwd()
    build()
    p_path = "../../client_proj/{pname}".format(pname=pname)
    rel_path = os.path.abspath("{rel}/assets/cclibs".format(rel=p_path))
    if not os.path.isdir(rel_path):
        os.makedirs(rel_path)
    os.chdir(pwd)
    
    for f in install_flist:
        cmd_str = "cp -f {f} {t}".format(f="_build/" + f, t = os.path.join(rel_path, f))
        print(cmd_str)
        os.system(cmd_str)
    print("Done!")

if __name__ == "__main__":
    pname = sys.argv[1]
    
    comile_and_move(pname)

